<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <button onclick="startTime()">开始定时器</button>
    <button onclick="stopTime()">停止定时器</button>
    <button onclick="startTime2()">延迟执行</button>
    <button onclick="stopTime2()">紧急停止</button>

    <script>
        var timer = null;
        var timer2 = null;
        function startTime(){
            timer = setInterval(function(){
                console.log(new Date().getTime());
            },1000);
        }

        function stopTime(){
            clearInterval(timer);
        }

        function startTime2(){
            timer2 = setTimeout(function(){
                console.log(new Date().getTime());
            },5000);
        }

        function stopTime2(){
            clearTimeout(timer2);
        }
        
    </script>
</body>
</html>